home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / mermaid.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  5KB  |  191 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char* mermaid_background_videoram;
  15. unsigned char* mermaid_foreground_videoram;
  16. unsigned char* mermaid_foreground_colorram;
  17. unsigned char* mermaid_background_scrollram;
  18. unsigned char* mermaid_foreground_scrollram;
  19.  
  20.  
  21. static struct rectangle spritevisiblearea =
  22. {
  23.     0*8, 26*8-1,
  24.     2*8, 30*8-1
  25. };
  26.  
  27. /***************************************************************************
  28.  
  29.   Convert the color PROMs into a more useable format.
  30.  
  31.   I'm not sure about the resistor value, I'm using the Galaxian ones.
  32.  
  33. ***************************************************************************/
  34. void mermaid_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  35. {
  36.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  37.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  38.  
  39.     int i;
  40.  
  41.     /* first, the char acter/sprite palette */
  42.     for (i = 0;i < TOTAL_COLORS(0); i++)
  43.     {
  44.         int bit0,bit1,bit2;
  45.  
  46.         /* red component */
  47.         bit0 = (*color_prom >> 0) & 0x01;
  48.         bit1 = (*color_prom >> 1) & 0x01;
  49.         bit2 = (*color_prom >> 2) & 0x01;
  50.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  51.         /* green component */
  52.         bit0 = (*color_prom >> 3) & 0x01;
  53.         bit1 = (*color_prom >> 4) & 0x01;
  54.         bit2 = (*color_prom >> 5) & 0x01;
  55.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  56.         /* blue component */
  57.         bit0 = 0;
  58.         bit1 = (*color_prom >> 6) & 0x01;
  59.         bit2 = (*color_prom >> 7) & 0x01;
  60.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  61.  
  62.         color_prom++;
  63.     }
  64.  
  65.     /* blue background */
  66.     *(palette++) = 0;
  67.     *(palette++) = 0;
  68.     *(palette++) = 0xff;
  69.  
  70.     /* set up background palette */
  71.     COLOR(2,0) = 32;
  72.     COLOR(2,1) = 33;
  73.  
  74.     COLOR(2,2) = 64;
  75.     COLOR(2,3) = 33;
  76. }
  77.  
  78.  
  79. /***************************************************************************
  80.  
  81.   Draw the game screen in the given osd_bitmap.
  82.   Do NOT call osd_update_display() from this function, it will be called by
  83.   the main emulation engine.
  84.  
  85. ***************************************************************************/
  86. void mermaid_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  87. {
  88.     int offs;
  89.  
  90.  
  91.     /* for every character in the backround RAM, check if it has been modified */
  92.     /* since last time and update it accordingly. */
  93.     for (offs = 0; offs < videoram_size; offs ++)
  94.     {
  95.         int code,sx,sy;
  96.  
  97.  
  98.         sy = 8 * (offs / 32);
  99.         sx = 8 * (offs % 32);
  100.  
  101.         code = mermaid_background_videoram[offs];
  102.  
  103.         drawgfx(tmpbitmap,Machine->gfx[2],
  104.                 code,
  105.                 (sx >= 26*8) ? 0 : 1,
  106.                 0,0,
  107.                 sx,sy,
  108.                 0,TRANSPARENCY_NONE,0);
  109.     }
  110.  
  111.  
  112.     /* copy the temporary bitmap to the screen */
  113.     {
  114.         int i, scroll[32];
  115.  
  116.  
  117.         for (i = 0;i < 32;i++)
  118.         {
  119.             scroll[i] = -mermaid_background_scrollram[i];
  120.         }
  121.  
  122.  
  123.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  124.     }
  125.  
  126.  
  127.     /* draw the front layer. They are characters, but draw them as sprites */
  128.     for (offs = 0; offs < videoram_size; offs ++)
  129.     {
  130.         int code,sx,sy;
  131.  
  132.  
  133.         sy = 8 * (offs / 32);
  134.         sx =     (offs % 32);
  135.  
  136.         sy = (sy - mermaid_foreground_scrollram[sx]) & 0xff;
  137.  
  138.         code = mermaid_foreground_videoram[offs] | ((mermaid_foreground_colorram[offs] & 0x30) << 4);
  139.  
  140.         drawgfx(bitmap,Machine->gfx[0],
  141.                 code,
  142.                 mermaid_foreground_colorram[offs] & 0x0f,
  143.                 0,0,
  144.                 8*sx,sy,
  145.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  146.     }
  147.  
  148.  
  149.     /* draw the sprites */
  150.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  151.     {
  152. #ifdef MAME_DEBUG
  153.         extern int debug_key_pressed;
  154. #endif
  155.         UINT8 flipx,flipy,sx,sy,code,bank = 0;
  156.  
  157.  
  158.         sx = spriteram[offs + 3] + 1;
  159.         sy = 240 - spriteram[offs + 1];
  160.         flipx = spriteram[offs + 0] & 0x40;
  161.         flipy = spriteram[offs + 0] & 0x80;
  162.  
  163.         /* this doesn't look correct. Oh really? Maybe there is a PROM. */
  164.         switch (spriteram[offs + 2] & 0xf0)
  165.         {
  166.         case 0x00:  bank = 2; break;
  167.         case 0x10:  bank = 1; break;
  168.         case 0x20:  bank = 2; break;
  169.         case 0x30:  bank = 3; break;
  170.         case 0x50:  bank = 1; break;
  171.         case 0x60:  bank = 2; break;
  172.         case 0x80:  bank = 0; break;
  173.         case 0x90:  bank = 3; break;
  174.         case 0xa0:  bank = 2; break;
  175.         case 0xb0:  bank = 3; break;
  176. #ifdef MAME_DEBUG
  177.         default:  debug_key_pressed = 1; break;
  178. #endif
  179.         }
  180.  
  181.         code = (spriteram[offs + 0] & 0x3f) | (bank << 6);
  182.  
  183.         drawgfx(bitmap,Machine->gfx[1],
  184.                 code,
  185.                 spriteram[offs + 2] & 0x0f,
  186.                 flipx, flipy,
  187.                 sx, sy,
  188.                 &spritevisiblearea,TRANSPARENCY_PEN,0);
  189.     }
  190. }
  191.